package com.xiangban.util;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

import static com.xiangban.utils.HttpUtils.sendPost;

/**
 * @Author ly
 * @date 2021/12/24 9:29
 */
@Slf4j
public class AmapUtil {
    private static  String key = "6d77b7119a4fb52745394ea5590ccf52";

    public static String getAdd(String log, String lat) throws Exception {
        StringBuffer s = new StringBuffer();
        s.append("key=").append(key).append("&location=").append(log).append(",").append(lat);
        String res = sendPost("http://restapi.amap.com/v3/geocode/regeo", s.toString());
        JSONObject jsonObject = JSONObject.parseObject(res);
        Map<String, Object> map = (Map<String, Object>) jsonObject.get("regeocode");
        String formatted_address = map.get("formatted_address").toString();


        return formatted_address;
    }


}
